package com.sjms._06_结构_外观模式;

/**
 * 兑换系统
 */
public class ExchangeSystem {
    BookSystem bookSystem = new BookSystem();
    JiFenSystem jiFenSystem = new JiFenSystem();
    WuLiuSystem wuLiuSystem = new WuLiuSystem();

    /**
     * 兑换图书
     */
    String convertBook(String bookName) {

        //积分系统扣积分
        String status = jiFenSystem.deductBook(bookName);
        if (status == null) {
            System.out.println("兑换《" + bookName + "》失败，积分不足");
            return null;
        }

        //图书系统兑换图书
        String book = bookSystem.getBook(bookName);
        if (book == null) {
            System.out.println("兑换失败，图书库存不足");
            return null;
        }


        //物流系统发货
        String transportStatus = wuLiuSystem.transportBook(book);
        if (transportStatus == null) {
            System.out.println("兑换失败，物流系统异常");
            return null;
        }
        return "ok";
    }
}
